// 管理员统计控制器
package org.example.backend.controller;

import org.example.backend.dto.StatisticsDto;
import org.example.backend.dto.SystemStatusDto;
import org.example.backend.service.StatisticsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/admin/statistics")
@CrossOrigin
@PreAuthorize("hasRole('ADMIN')")
public class AdminStatisticsController {

    private static final Logger logger = LoggerFactory.getLogger(AdminStatisticsController.class);

    private final StatisticsService statisticsService;

    public AdminStatisticsController(StatisticsService statisticsService) {
        this.statisticsService = statisticsService;
    }

    /**
     * 获取实习统计数据
     */
    @GetMapping("/internship")
    public ResponseEntity<StatisticsDto> getInternshipStatistics() {
        try {
            StatisticsDto statistics = statisticsService.getInternshipStatistics();
            return ResponseEntity.ok(statistics);
        } catch (Exception e) {
            logger.error("获取实习统计数据失败", e);
            return ResponseEntity.badRequest().build();
        }
    }

    /**
     * 获取系统运行状态
     */
    @GetMapping("/system")
    public ResponseEntity<SystemStatusDto> getSystemStatus() {
        try {
            SystemStatusDto status = statisticsService.getSystemStatus();
            return ResponseEntity.ok(status);
        } catch (Exception e) {
            logger.error("获取系统状态失败", e);
            return ResponseEntity.badRequest().build();
        }
    }
}
